<?php

//echo 'ciao';

// recupero via post gli indirizzi mail degli amici e invio le mail
// per partecipare al group gift


include($_SERVER['DOCUMENT_ROOT'] . '/installdb/class.DBmanager.php');

include('api.php');


$comment = '';
$question = '';

$yes_no_options = array();

if (isset($_POST['comment-box']))
	$comment = $_POST['comment-box'];

if (isset($_POST['radio_y_n']))
	$question = $_POST['radio_y_n'];

if (isset($_POST['survey_yes_options']))
    $yes_no_options = $_POST['survey_yes_options'];

else if (isset($_POST['survey_no_options']))
    $yes_no_options = $_POST['survey_no_options'];


//echo $comment . ' ' . $question;


// salvataggio su file di testo
try {
    $myFile = "survey.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    $stringData = "#" . $question . '#';

    $str_opt = '';
    foreach($yes_no_options as $opt){
        $str_opt .= '' . $opt . '#';
    }

    $stringData .= $str_opt;

    $stringData .= '' . $comment . "\n";

    fwrite($fh, $stringData);
    fclose($fh);

    // redirect alla home
    header('Location: /home.php');

    // send mail
    send_mail_tracking_survey($stringData);

}
catch(Exception $e) {}



/* MYSQLi */

/*
$db = DBManager::getInstance();
$conn = $db->db_connect_mysqli();
$query = "SELECT * FROM users_prereg";

try {
 $result = $db->db_query_mysqli($query);


echo mysqli_num_rows($result);
}
catch (Exception $e) {
	
	echo 'Error';
}
*/



?>